/**
 * 创建人:冯斌    创建日期:2008-2-12
 */
package com.wsj.util.tool;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

/**
 * @author fengbin
 *url链接处理工具
 */
public class UrlUtil 
{
    //处理url  
    public static String dealurl(HttpServletRequest request)
    {
     String url = "";
      
//     url = request.getRequestURL()+"?";
     url = request.getServletPath()+"?";
     url +=param(request);
     if(url.indexOf("&")>-1)
      url=url.replaceAll("&","@#@");//实际上就是把有&的字符转化成了@#@
     return url;
    }
    
    //还原url
    public static String geturl(String url)
    {
     if(url.indexOf("@#@")>-1)
      url=url.replaceAll("@#@","&");
     return url;     
    }
    
    
    public static String param(HttpServletRequest request)
    {
     String url = "";
     Enumeration param = request.getParameterNames();//得到所有参数名
     while(param.hasMoreElements())
     {
      String pname = param.nextElement().toString();
      url += pname+"="+request.getParameter(pname)+"&";
     }
     if(url.endsWith("&"))
     {
      url = url.substring(0,url.lastIndexOf("&"));
     }
     return url;
    }
   }
